package com.mhc.suzuki.controller;

import com.mhc.suzuki.constant.ErrorCodeEnum;
import com.mhc.suzuki.service.CarModelService;
import com.mhc.suzuki.vo.CarModelVO;
import com.subaru.common.entity.BizResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 车型管理
 * Created by kanon on 17/9/27 19:18.
 */
@Slf4j
@RestController
@RequestMapping(value = "/carModel")
public class CarModelController {

    @Autowired
    private CarModelService carModelService;

    /**
     * 获取车型
     *
     * @param keyword
     * @return
     */
    @ApiOperation(value = "获取车型", notes = "")
    @RequestMapping(value = {"/{keyword}"}, method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", paramType = "path", value = "搜索关键字", required = true),
    })
    public BizResult<List<CarModelVO>> getCarModelList(@PathVariable String keyword) {
        if(StringUtils.isBlank(keyword)){
            return BizResult.create(ErrorCodeEnum.PARAM_EMPTY.getErrCode(), ErrorCodeEnum.PARAM_EMPTY.getErrMsg());
        }
        BizResult<List<CarModelVO>> bizResult = new BizResult<>();
        bizResult.setData(carModelService.getCarModelListCache(keyword));
        bizResult.setMessage("获取车型成功");
        bizResult.setSuccess(true);
        return bizResult;
    }

}